<?php

class NumericUtilities
{
	/*
	 * Given an array of odds, randomly calculate the wedge that is hit
	 * This wedge is expressed at the array index of the odds array element
	 * Numbers are percentages
	 */
	public static function spinRoulette($odds)
	{
		// Temporary fix in case of -1
		// Need to investigate root cause
		//$hitWedge = -1;
		$hitWedge = 0;
		
		$wedgeMin = 0;
		$wedgeMax = 0;
		
		$shoot = rand( 1, 100 );
		
		for( $ind = 0; $ind < count($odds); $ind++ )
		{
			$wedgeMax = $wedgeMin + $odds[$ind];
			
			if( ($shoot > $wedgeMin) && ($shoot <= $wedgeMax) )
			{
				$hitWedge = $ind;
				break;
			}
			
			$wedgeMin = $wedgeMax;
		}
		
		return $hitWedge;
	}
	
}
